<template>
	<!-- 个人资料 -->
	<view class="personal">
		<!-- #ifdef APP-PLUS -->
		<top-set></top-set>
		<tab-top fixed="true" title="个人资料"></tab-top>
		<!-- #endif -->
		<view class="bg_01"></view>
		<view class="set_box">
			<!-- 个人头像 -->
			<view class="set_item" @tap="upload()">
				<view class="set_item_left">
					<text>个人头像</text>
				</view>
				<view class="set_item_reght">
					<image class="img" :src="src ||'/static/bg/img.png'"></image>
					<image src="/static/personal-center/right.png"></image>
				</view>
			</view>
			<!-- 用户昵称 -->
			<view class="set_item" @tap="goSet('nickname')">
				<view class="set_item_left">
					<text>用户昵称</text>
				</view>
				<view class="set_item_reght">
					<text>{{username}}</text>
					<image src="/static/personal-center/right.png"></image>
				</view>
			</view>
			<!-- 个性签名 -->
			<view class="set_item" @tap="goSet('signature')">
				<view class="set_item_left">
					<text>个性签名</text>
				</view>
				<view class="set_item_reght">
					<text>{{title}}</text>
					<image src="/static/personal-center/right.png"></image>
				</view>
			</view>
		</view>	
		<view class="bg_02"></view>
		<view class="set_box">
			<!-- 常驻地址 -->
			<view class="set_item" @tap="map()">
				<view class="set_item_left">
					<text>常驻地址</text>
				</view>
				<view class="set_item_reght">
					<text class="text">{{address}}</text>
					<image src="/static/personal-center/right.png"></image>
				</view>
			</view>
			<!-- 手机号码 -->
			<!-- <view class="set_item" @tap="goSet('phone')"> -->
			<view class="set_item">
				<view class="set_item_left">
					<text>手机号码</text>
				</view>
				<view class="set_item_reght">
					<text>{{phone}}</text>
					<!-- <image src="/static/personal-center/right.png"></image> -->
				</view>
			</view>
			<!-- 登录密码 -->
			<view class="set_item" @tap="goSet('password')">
				<view class="set_item_left">
					<text>登录密码</text>
				</view>
				<view class="set_item_reght">
					<image src="/static/personal-center/right.png"></image>
				</view>
			</view>
		</view>	
	</view>
</template>

<script>
	let userAdress;
	export default {
		data() {
			return {
				address:''
			}
		},
		methods: {
			goSet(url){
				uni.navigateTo({
					url: '/pages/user/set/' + url
				});
			},
			map(){
				uni.chooseLocation({
					success: (res) => {
						this.address = res.name
						this.req({
							url:'user/cleaner',
							method:"PUT",
							id:this.isLogin().id,
							data:{
								address:this.address,
								address_name:res.address,
								latitude:res.latitude,
								longitude:res.longitude,	
							}
						},(resp)=>{
							this.modifyUserInfo('address', this.address);
							this.updateUserInfo();
						})
					}
				})
			},
			upload() {
				uni.chooseImage({
					count: 1, // 默认9
					sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success(res) {
						const src = res.tempFilePaths[0];
						uni.navigateTo({
							url: '/pages/user/set/avatar?src='+src
						});
					}
				});
			},
		},
		onLoad(e) {
			/**
			 * 获取头像
			 */
			let { avatar } = e;
			if (avatar) {
				this.src = avatar;
			}
			if(this.$store.state.address){
				this.address = this.$store.state.address;
			}
		},
		computed: {
			src(){
				if(this.$store.state.avatarUrl){
					return this.$store.state.avatarUrl;
				}
			},
			username(){
				if(this.$store.state.username){
					return this.$store.state.username;
				}
				return "用户名未填写";
			},
			title(){
				if(this.$store.state.title){
					return this.$store.state.title;
				}
				return "个性签名未填写";
			},
			phone(){
				if(this.$store.state.phone){
					return this.$store.state.phone;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.personal{
	font-family: PingFang-SC-Medium;
	font-weight: normal;
	font-stretch: normal;
	letter-spacing: 0px;
	color: #333333;
	.set_box{
		width: 702upx;
		height: 296upx;
		padding: 0 24upx;
		.set_item{
			height: 98upx;
			width: 702upx;
			border-bottom: 1upx solid #e5e5e5;
			line-height: 98upx;
			display: flex;
			justify-content: space-between;
			.set_item_left{
				font-size: 28upx;
				z-index: 99;
			}
			.set_item_reght{
				font-size: 28upx;
				color: #999999;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				.text{
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					text-align: end;
					width: 450upx;
				}
				.img{
					width: 80upx;
					height: 80upx;
					border-radius: 50%;
					margin-right: 8upx;
					// will-change: transform;
				}
				image{
					width: 9upx;
					height: 18upx;
					margin-left: 12upx;
				}
			}
		}
	}
	.bg_01{
		width: 750upx;
		height: 30upx;
		background-color: #f0f0f0;
	}
	.bg_02{
		width: 750upx;
		height: 10upx;
		background-color: #f0f0f0;
	}
}
</style>

